﻿@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
    ViewBag.Title = "服务";
}
<div class="">
    <div class="ibox-content">
        <div class="jqGrid_wrapper">
            <div class="col-sm-12 jqGrid-toolbar">
                <form id="form-changepass" action="/TcpServer/Open" method="post">
                    <label>IP：</label><input id="ip" name="ip" value="" />
                    <label>端口：</label><input id="port" name="port" />
                    <button type="submit" id="but_Sub">开启服务</button>
                </form>
            </div>
            <table id="grid"></table>
            <div id="grid_pager"></div>
        </div>
    </div>
</div>
@section BodyFooter{
    <script>
        $(document).ready(function () {

            $("#grid").jqGrid({
                url: '/TcpServer/Query',
                colNames: ["ID", "客户端代码", "名称", "IP", "物业ID", "物业名", "停车场ID", "停车场名", "支付加密串", "状态", "创建时间"],
                colModel: [{
                    name: "ID",
                    index: "ID",
                    key: true,
                    width: 30
                },
                {
                    name: "DeviceClient_code",
                    index: "DeviceClient_code",
                    width: 120
                },
                {
                    name: "Device_name",
                    index: "Device_name",
                    width: 120
                },
                {
                    name: "Device_IP",
                    index: "Device_IP",
                    width: 80
                },
                {
                    name: "Enterprise_ID",
                    index: "Enterprise_ID",
                    width: 40
                },
                 {
                     name: "Enterprise_name",
                     index: "Enterprise_name",
                     width: 80
                 },
                  {
                      name: "TcEnterprise_ID",
                      index: "TcEnterprise_ID",
                      width: 40
                  },
                  {
                      name: "TcEnterprise_name",
                      index: "TcEnterprise_name",
                      width: 80
                  }
                  ,
                  {
                      name: "Api_secret",
                      index: "Api_secret",
                      width: 120
                  },
                  {
                      name: "version",
                      index: "version",
                      width: 90,
                      sortable: false,
                      formatter: version
                  }
                  ,
                {
                    name: "create_time",
                    index: "create_time",
                    width: 120,
                    formatter: 'date',
                    formatoptions: { newformat: 'Y-m-d H:i:s' }
                }],
                caption: "TCP服务",
            });

            $("#grid").adaptGridSizeInWindow();
            window.setInterval("reloadData()", 10 * 1000);
            window.setInterval("YpayFee()", 1000);
            window.setInterval("QueryUpinoPay()", 3*1000);
        });
        var reloadData = function () {
            $("#grid").jqGrid('setGridParam', {
                page: 1
            }).trigger("reloadGrid"); //重新载入
        }
        var YpayFee = function () {
            common.postAjax('/TcpServer/QueryYPay', function (result) {
            });
        }
        var QueryUpinoPay = function () {
            common.postAjax('/TcpServer/QueryUpinoPay', function (result) {
            });
        }
        var common = {
            postAjax: function (url, data, success) {
                var hs = document.getElementsByName('__RequestVerificationToken');
                if (hs.length > 0) {
                    data = data || {};
                    data["__RequestVerificationToken"] = hs[0].value;
                }
                $.ajax({
                    url: url,
                    cache: false,
                    type: 'post',
                    dataType: 'json',
                    data: data,
                    success: success
                });
            }
        };
        function version(cellvalue, options, rowObject) {
            var st = rowObject['version'];
            if (st == 10) {
                return "在线";
            } else {
                return "掉线";
            }
        }
        $(function () {
            $.validator.setDefaults({
                submitHandler: function (form) {
                    $(form).ajaxSubmit(function (d) {
                        if (d.Code == 1) {
                            // toastr.info('服务开启成功');
                            document.getElementById("but_Sub").disabled = true
                            alert('服务开启成功');
                        } else {
                            alert(d.Message);
                        }
                    });
                }
            });

            $('#form-changepass').validate()
        });
    </script>
}
